from urllib import request

# respose = request.urlopen('http://httpbin.org/get',data=b'username=bbb&password=123')
respose = request.urlopen('http://httpbin.org/post', data=b'username=bbb&password=123')
# print(respose)
'''
try:
    respose1 = request.urlopen('http://www.baidu.com',timeout=0.001)
    print(respose1)
except:
    print("Time out")






heades = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"}
req = request.Request("http://www.baidu.com",heades=heades)
response2 = request.urlopen(req)
'''

from http import cookiejar

'''
cookie = cookiejar.CookieJar()

cookies = request.HTTPCookieProcessor(cookie)

openner = request.build_opener(cookies)

respose = openner.open("http://www.baidu.com")

print(cookies.cookiejar)
'''

'''

url = 'http://httpbin.org/ip'

# {"协议":"ip:端口"}

proxy = {"http":"122.91.116.50:6673"}

proxies = request.ProxyHandler(proxy)

openner = request.build_opener(proxies)
res = openner.open(url)
print(res.read().decode())

'''

respose1 = request.urlopen('http://www.baidu.com')
# while True:
#     if respose1.readline() is None:
#         break
#     dd = respose1.readline()
#     print(dd)
#     with open(r"C:\Users\Administrator\Documents\python\yy.txt","wb+") as f:
#        f.write(dd)
#    print(respose1.readline())
print(respose1.info())
